package com.sys.SysSales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sys.common.annotation.Log;
import com.sys.common.core.controller.BaseController;
import com.sys.common.core.domain.AjaxResult;
import com.sys.common.enums.BusinessType;
import com.sys.SysSales.domain.SysSalesCustomers;
import com.sys.SysSales.service.ISysSalesCustomersService;
import com.sys.common.utils.poi.ExcelUtil;
import com.sys.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author ruoyi
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/SysSales/SysSalesCustomers")
public class SysSalesCustomersController extends BaseController
{
    @Autowired
    private ISysSalesCustomersService sysSalesCustomersService;

    /**
     * 查询客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('SysSales:SysSalesCustomers:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSalesCustomers sysSalesCustomers)
    {
        startPage();
        List<SysSalesCustomers> list = sysSalesCustomersService.selectSysSalesCustomersList(sysSalesCustomers);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('SysSales:SysSalesCustomers:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSalesCustomers sysSalesCustomers)
    {
        List<SysSalesCustomers> list = sysSalesCustomersService.selectSysSalesCustomersList(sysSalesCustomers);
        ExcelUtil<SysSalesCustomers> util = new ExcelUtil<SysSalesCustomers>(SysSalesCustomers.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('SysSales:SysSalesCustomers:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(sysSalesCustomersService.selectSysSalesCustomersByCustomerId(customerId));
    }

    /**
     * 新增客户信息
     */
    @PreAuthorize("@ss.hasPermi('SysSales:SysSalesCustomers:add')")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSalesCustomers sysSalesCustomers)
    {
        return toAjax(sysSalesCustomersService.insertSysSalesCustomers(sysSalesCustomers));
    }

    /**
     * 修改客户信息
     */
    @PreAuthorize("@ss.hasPermi('SysSales:SysSalesCustomers:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSalesCustomers sysSalesCustomers)
    {
        return toAjax(sysSalesCustomersService.updateSysSalesCustomers(sysSalesCustomers));
    }

    /**
     * 删除客户信息
     */
    @PreAuthorize("@ss.hasPermi('SysSales:SysSalesCustomers:remove')")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(sysSalesCustomersService.deleteSysSalesCustomersByCustomerIds(customerIds));
    }

    /**
     * 根据客户查询产品数量
     */
    @GetMapping(value = "/quantities/{customerId}")
    public TableDataInfo quantities(@PathVariable("customerId") Long customerId){
        startPage();
        List<SysSalesCustomers> list = sysSalesCustomersService.selectProductSalesAndTotalByCustomerId(customerId);
        return getDataTable(list);
    }
}
